//
//  FPNoDataController.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/1/22.
//

#import "FPNoDataController.h"

@interface FPNoDataController () <DZNEmptyDataSetSource , DZNEmptyDataSetDelegate , UITableViewDelegate , UITableViewDataSource>

@end

@implementation FPNoDataController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = UIColor.whiteColor;
    
    NSString *text;
    
    if (self.type == RecordListTypeRepay) {
        
        text = @"还款记录";
    }
    else if (self.type == RecordListTypeLoan) {
        
        text = @"借贷记录";
    }
    else if (self.type == RecordListTypeReviewFailure || self.type == RecordListTypeLoanInReview) {
        
        text = @"借款详情";
    }
    else if (self.type == RecordListTypeInReview) {
        
        text = @"资料审核";
        
        // 删除控制器
        NSMutableArray *marr = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
        
        for (UIViewController *vc in marr) {
        
            if ([vc isKindOfClass:NSClassFromString(@"FPProfileEditorController")]) {
                
                [marr removeObject:vc];
                break;
            }
        }
        
        for (UIViewController *vc in marr) {
        
            if ([vc isKindOfClass:NSClassFromString(@"FPMeProfileController")]) {
                
                [marr removeObject:vc];
                break;
            }
        }
        
        for (UIViewController *vc in marr) {
            
            if ([vc isKindOfClass:NSClassFromString(@"FPAuthenticationController")]) {
                
                [marr removeObject:vc];
                
                break;
            }
        }
        
        self.navigationController.viewControllers = marr;
    }
    
    [self setTitle:text style:(XYCustomNavigationStyleWhite) hiddenBackBtn:NO];
    
    [self.view addSubview:self.tableView];
    self.tableView.emptyDataSetSource = self;
    self.tableView.emptyDataSetDelegate = self;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return UITableViewCell.new;
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    
    if (self.type == RecordListTypeInReview) {
    
        return IMG(@"bg_nodata_inreview");
    }
    else if (self.type == RecordListTypeReviewFailure) {
    
        return IMG(@"bg_nodata_loan_review_failure");
    }
    else {
     
        return IMG(@"bg_nodata");
    }
}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {

    return - 80.f;
}

- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state {
    
    NSString *text;
    
    if (self.type == RecordListTypeRepay) {
        
        text = @"暂无还款记录";
    }
    else if (self.type == RecordListTypeLoan) {
        
        text = @"暂无借款记录";
    }
    else if (self.type == RecordListTypeReviewFailure) {
        
        text = @"原因：综合评估不足，请保持良好的消费记录";
    }
    else if (self.type == RecordListTypeLoanInReview) {
        
        text = @"我们正在审核您的借款申请，请耐心等待审核结果";
    }
    else if (self.type == RecordListTypeInReview) {
        
        text = @"我们正在快马加鞭处理您的申请资料请耐心等待审核结果";
    }
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    
    [NSString stringToAttribute:attStr font:FONT(12.f) range:NSMakeRange(0, text.length)];
    [NSString stringToAttribute:attStr color:[UIColor hexColor:@"#6A6A6A"] range:NSMakeRange(0, text.length)];

    return attStr;
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    
    NSString *text;
    
    if (self.type == RecordListTypeInReview) {
        
        text = @"您提交的资料正在审核中";
    }
    else if (self.type == RecordListTypeLoanInReview) {
        
        text = @"借款审核中";
    }
    else if (self.type == RecordListTypeReviewFailure) {
        
        text = @"抱歉，放款失败";
    }
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    
    [NSString stringToAttribute:attStr font:BFONT(16.f) range:NSMakeRange(0, text.length)];
    [NSString stringToAttribute:attStr color:[UIColor hexColor:@"#3A3A3A"] range:NSMakeRange(0, text.length)];
    
    return attStr;
}

@end
